-
-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The possibility to specify a path to the settings file #41
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great PR, I've commented on a couple of nitpicks but nothing major! Thanks for taking the time to add proper tests as well. Looking forward to merging this one 👍
|
||
class FileConfigManager implements ConfigManager | ||
{ | ||
private const SETTINGS_FILE_NAME = '.ignition.json'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can rename this to CONFIG_FILE_NAME
to keep it in line with the ConfigManager
, etc...
private const SETTINGS_FILE_NAME = '.ignition.json'; | |
private const CONFIG_FILE_NAME = '.ignition.json'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello,
I kind of agree, but to me, the config/ignition.php
is a config file and .ignition.json
is a settings file. One of the reasons for this separation is the Laravel Ignition button naming (we have a Save settings button there). So, not to confuse users I tried to differentiate these two concepts by introducing this term settings file
. That's why I would like to stick to this name settings file
and use it for this file if you don't mind.
However, if you don't like this differentiation at all let's change it. @AlexVanderbist please let me know about your decision.
src/Config/FileConfigManager.php
Outdated
return rtrim($path, DIRECTORY_SEPARATOR); | ||
} | ||
|
||
public function createSource(): bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
createSource
might be a bit vague. Maybe we can rename it to something a bit more explicite?
public function createSource(): bool | |
public function createConfigFile(): bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I totally agree that the term source
is vague. However, I tried to make the contract as abstract as possible (in case if in the future somebody is going to use a database or other persistent source to keep the settings). If there is no need for the abstraction let's rename it according to your final decision about the config
or settings
file above. But if there is a chance that the persistent source will have changed in the future, let's try to come up with a less vague definition for that (for example Storage
).
@AlexVanderbist please let me know about your decision.
src/Config/FileConfigManager.php
Outdated
return rtrim($path, DIRECTORY_SEPARATOR); | ||
} | ||
|
||
public function createSource(): bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, what do you think about calling this method from the save()
method? We can still keep it public for use inside of tests tho.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea to introduce and make createSource()
method public was to give the possibility to create a settings storage somewhere outside. For example, if I don't want to use the createSource
every time on the saving operation, I can just use it in a ServiceProvider to create it once. So, I'm still thinking about how to implement it and you are absolutely right that it's better to remove this call from IgnitionConfig.php
.
I need to think about a better solution on how to create storage once and not use it on every save() call. Until then, I'll move it to the save() method.
src/Config/IgnitionConfig.php
Outdated
if (! function_exists('app')) { | ||
return new FileConfigManager(); | ||
} | ||
|
||
return app(ConfigManager::class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting approach! :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Frankly speaking, this approach is a little bit dangerous, because it leads to an exception if there is no bound instance in the container (according to PSR-11 and according to the Larave documentation). In my view, this is the case where fail fast
looks better than fail soft
.
src/Config/IgnitionConfig.php
Outdated
} catch (Throwable) { | ||
return false; | ||
} | ||
$this->manager->createSource(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this call be moved to inside of the $manager->save()
method?
src/Contracts/ConfigManager.php
Outdated
/** @return array<string, mixed> */ | ||
public function load(): array; | ||
|
||
/** @param array<string, mixed> $options */ | ||
public function save(array $options): bool; | ||
|
||
/** @return array<string, mixed> */ | ||
public function getSource(): array; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think these doc block typehints add a lot (I know we've used them in other places as well and I should really go over those and clean up 😅)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather leave them. At least, they show that they are expected to be associative arrays :)
…ws environment test.
…erate filepath method.
…indows environment test.
… filepath method.
…te filepath method.
…punit built-in method.
…e in the non-windows environment.
…e in the windows environment.
…llFilePath method.
…dFromFile method.
…eFullFilePath method.
…FromArgument method.
…ateSource method.
… call from some tests.
…nvironment method.
…initConfigManager method.
@AlexVanderbist I tried to push it gently but without any luck. Sorry for that 😭 I should've made another PR from another branch, probably. I don't know how to cope with such situations when the only option is to push with force. What are your suggestions, btw? So, this is a modified solution reworked by taking into account suggestions and some new ideas:
, that looks better to me and more self-explantory
Besides these refinements, I have finished a branch with the integration of these changes to the As an afterthought, I would like to propose to extract the functionality based on user's home directory (everything under the initPathFromEnvironment()) to another class. It's not really crucial, but it is obviously sort of my fault, that I mixed them up. It seems like these (use predefined filename vs use the dynamically retrieved user home directory) are two different responsibilities with different functionality (works per project vs works for all the projects). So, it is better to do in the future. |
I'd better close it. |
Hey @kudashevs, sorry about the delay. I didn't mean to come across as disrespectful or uninterested. If you would still like to see this PR merged, feel free to re-open it and I'll be happy to continue looking at it. |
Hello @AlexVanderbist No worries. I just thought that the proposition is not still interesting (because it turned out to be kind of messy, big, and complicated). Let's try it one more time. If you don't mind I'm going to open a new PR. |
Awesome, thanks! I'll go over it later today 👍 |
Hello again 👋,
This is a draft PR of the first step of a proposition to the
laravel-ignition
.This is a new component
FileConfigManager
which is implemented through a newConfigManager
interface. The interface is a little bit over-engineered with thegetSource
method, however, I've found it useful for testing purposes and it could be useful in the future (but it could be removed, though). So, the newFileConfigManager
gets all the responsibility to manage the settings file: